-
-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add Serialize/Deserialize for ActiveValue #1631
base: master
Are you sure you want to change the base?
Conversation
Add Serialize/Deserialize for ActiveValue behind the "with-json" feature flag
What's the current status of this PR? It looks like exactly what I need. I'm happy to push it over the finish line as well |
@@ -36,6 +38,7 @@ pub use ActiveValue::NotSet; | |||
/// ); | |||
/// ``` | |||
#[derive(Clone, Debug)] | |||
#[cfg_attr(feature = "with-json", derive(Serialize, Deserialize))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use sea_query's value_to_json
to handle the Serialize
part, but in general ActiveValue does not seem to lend itself for Deserialize
, because the trait bound only requires T -> Value
.
Thank you for the contribution! Do you really needed May be also add some test cases under |
Add Serialize/Deserialize for ActiveValue
PR Info
As of right now there exists "with-json" feature flag, which allows applying changes to an ActiveModel through the JSON Value type. This could be useful when updating some data in the database by sending a JSON to the server through an HTTP API. An alternative way of doing the same thing would be to send the ActiveModel, with all its changes relative tp the Model, directly to the server. This requires the serialization of the ActiveModel. At the moment (sea-orm version 0.11) it is not possible due to Serialize/Deserialize traits not being implemented for ActiveValue. This PR adds the derive for these traits conditionally when the "with-json" feature is enabled. This way the Serialize/Deserialize traits implementation for the exact ActiveModel could be done by the library user, while the implementation for the ActiveValue is behind the feature flag.
New Features
Breaking Changes
Changes